package com.xxx.springboot.distributedsession;

import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Externalizable;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;

/**
 * 分布式session header
 */
@Data
@NoArgsConstructor
public class DistributedSessionHeader implements Externalizable {

    /**
     * 创建时间
     */
    private long createTime;
    /**
     * 是否为新创建
     */
    private boolean newBuild;
    /**
     * 最后一次访问时间
     */
    private long lastAccessTime;

    public DistributedSessionHeader(long createTime) {
        this.createTime = createTime;
    }

    @Override
    public void writeExternal(ObjectOutput out) throws IOException {
        out.writeLong(createTime);
        out.writeLong(lastAccessTime);
        out.writeBoolean(newBuild);
    }

    @Override
    public void readExternal(ObjectInput in) throws IOException {
        createTime = in.readLong();
        lastAccessTime = in.readLong();
        newBuild = in.readBoolean();
    }
}